<?php

class Kd_Html_Toolbar extends Kd_Html_Element {

    private $_groups = array();
    private $_sort = array();

    public function __construct() {
        parent::__construct();
        $this->templateName = 'toolbar';
    }

    public function createGroup($name = 'default') {
        if (!isset($this->_groups[$name])) {
            $this->_groups[$name] = new Kd_Html_Toolbar_Group();
        }
        return $this->_groups[$name];
    }

    public function removeGroup($name = 'default') {
        if (array_key_exists($name, $this->_groups)) {
            unset($this->_groups[$name]);
        }
        return $this;
    }

    public function getGroup($name) {
        if (array_key_exists($name, $this->_groups)) {
            return $this->_groups[$name];
        }
        return NULL;
    }

    public function getGroups() {
        return $this->_groups;
    }

    protected function render() {
        $result = '<div class="toolbar">';
        $result .= '<div class="toolbar-items">';
        foreach ($this->_groups as $name=>$group) {
        	$result .= $group->toHtml();
        }
        return $result . '</div></div>';
    }

}